home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 160 - Disc 1 / MF_UK_160_1.iso / pc / DiscContent / FullSoftware / Amapi61MacEn / Amapi 3D 6.1 Installer / 3SPACE / ShootBehavior.js < prev    next >
Encoding:
Text File  |  2001-02-20  |  2.0 KB  |  80 lines  |  [AMAS/AMAP]

  1. // -* ShootBehavior.js *-
  2. //
  3. // Name: Shoot behavior
  4. // Description: 
  5. // Author:
  6. // Version: $Id: ShootBehavior.js,v 1.11 2000/12/21 15:03:30 consumer Exp $
  7. //
  8.  
  9. // Keep an array of the solids using this behavior
  10. var shootSolids = new Array(1);
  11.  
  12. function ShootBehavior(solidName, camera, direction, intensity)
  13. {
  14.   // Member methods of the behavior
  15.   this.start = ShootBehaviorStart;
  16.   this.stop = ShootBehaviorStop;
  17.  
  18.   // Member variables of the behavior
  19.   this.solidName = solidName;
  20.   this.direction = direction;
  21.   this.intensity = intensity * TSSolidGetMass(solidName);
  22.   this.camera = camera;
  23. }
  24.  
  25. function ShootBehaviorStart()
  26. {
  27.   var position = TSSolidGetPosition(this.solidName);
  28.   var dampingID = TSMakeUniqID("DampingForce_" + this.solidName);
  29.   var shootID = TSMakeUniqID("ShootForce_" + this.solidName);
  30.   var shootDir;
  31.  
  32.   if (this.camera == "") {
  33.     shootDir = this.direction;
  34.   }
  35.   else {
  36.     // Calculate the direction of the shoot force
  37.     shootDir = TSMakeStringFromVector(TSVectorNormalize(TSMakeVector(TSCameraGetPosition(this.camera), position)));
  38.   }
  39.  
  40.   TSMakeDampingSolidForce(dampingID, 1.0, 0.5);
  41.   TSAppendChild(this.solidName, dampingID);
  42.  
  43.   TSMakeShootForce(shootID, shootDir, this.intensity, TSMakeStringFromPoint(position));
  44.   TSAppendChild(this.solidName, shootID);
  45.   TSUpdateNode(shootID);
  46.   TSUpdateNode(dampingID);
  47.   TSRemoveNode(shootID);
  48.   TSRemoveNode(dampingID);
  49. }
  50.  
  51. function ShootBehaviorStop()
  52. {
  53. }
  54.  
  55. //
  56. // Event functions
  57. //
  58.  
  59. function ShootBehaviorStartEvent(obj, event)
  60. {
  61.   if (shootSolids[obj] == null) {
  62.     var direction = TSGetExtraParam(event, 'direction');
  63.     var intensity = TSGetExtraParam(event, 'intensity');
  64.     var targetSolid = TSGetExtraParam(event, 'targetSolid');
  65.     var camera = TSGetExtraParam(event, 'camera');
  66.  
  67.     if (targetSolid == "")
  68.       shootSolids[obj] = new ShootBehavior(obj, camera, direction, intensity);
  69.     else
  70.       shootSolids[obj] = new ShootBehavior(targetSolid, camera, direction, intensity);
  71.   }
  72.     
  73.   shootSolids[obj].start();
  74. }
  75.  
  76. function ShootBehaviorStopEvent(obj, event)
  77. {
  78.   shootSolids[obj].stop();
  79. }
  80.